﻿using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using YogaStudio.Data;
using YogaStudio.Data.Domain;

namespace YogaStudio.Service.BLL
{
   public class CourseService : ICourseService
   {
       private IYogaStudioEntities db;

        public CourseService()
       {
           db = new YogaStudioEntities();
       }

       public CourseService(IYogaStudioEntities dbContext)
       {
           db = dbContext;
       }
       public List<Course> GetAllCourses()
       {
           return db.Courses.ToList();
       }
       public Course GetCourse(int id)
       {
           return db.Courses.Find(id);

       }
       public bool DeleteCourse(Course course)
       {
           if (course == db.Courses.Remove(course))
           {
               db.SaveChanges();
           }
               return true;

       }
       public void UpdateCourser(Course course)
       {
           db.Entry(course).State = EntityState.Modified;
          db.SaveChanges();
       }
       public void SaveCourse(Course course)
       {
           db.Courses.Add(course);
           db.SaveChanges();
       }
       public void Dispose(bool disposing)
       {
           if (disposing) db.Dispose();
       }
    }
}
